package chapter09;

import java.io.File;

public class FindFiles  implements Runnable
{
     //introduce the String  dir 
	private String dir;
	//introduce the String endfix 
	private String endFix;
	
		//constructor method make the introduce
	
	public FindFiles(String dir,String endFix)
	{
		this.dir=dir;
		this.endFix=endFix;
	}
	
	
    public java.util.List<String>  findFile(String dir,String endFix)
    {
    	java.util.List<String> fileNameList=new java.util.Vector();
    	java.io.File dirFile=new java.io.File(dir);
    	java.io.File[] fileArray=dirFile.listFiles();
    	
    	
    	for(int i=0;i<fileArray.length;i++){
			File temfile=fileArray[i];
			
			
			if(temfile.isFile())
			{
				String fileName=temfile.getAbsolutePath();
				
				if(fileName.endsWith(endFix))
				{
					fileNameList.add(fileName);
				}
			}
			
			

			if(temfile.isDirectory())
			{
				String dn=temfile.getAbsolutePath();
			
				java.util.List<String> newList=findFile(dn,endFix);
				
				fileNameList.addAll(newList);
			}
			if(fileNameList.size()>0)
				for(String s:fileNameList)
					System.out.println(s);
		}
		return fileNameList;
			
    	
    }

	public void run(){
		findFile(dir,endFix);
    }
}
